﻿#region Namespace References

using System;
using DynConDevCorp.OpenArch.SmartData.Core;
using DynConDevCorp.OpenArch.SmartData.Core.EntityTypeLevel;
using DynConDevCorp.OpenArch.SmartData.Interfaces.EventArgClasses;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DynConDevCorp.OpenArch.SmartData.Interfaces.Attributes;
using DynConDevCorp.OpenArch.SmartData.Interfaces;

#endregion

namespace UnitTest.DynConDevCorp.OpenArch.SmartData.FunctionalTests
{
    [TestClass]
    public class EffectPropogation_FunctionalTests
    {
        #region Public Instance Properties

        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        #endregion

        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup]
        //public void MyTestCleanup()
        //{
        //}
        //

        #region Public Instance Methods

        void ParentLevel_Instance_Effect(object sender, ValueChangedEventArgs<decimal> e)
        {
        }

        void ParentLevel_Type_Effect(object sender, ValueChangedEventArgs<decimal> e)
        {
        }

        void MidLevel_Effect(object sender, ValueChangedEventArgs<decimal> e)
        {
        }

        void EntityLevel_Effect(object sender, ValueChangedEventArgs<decimal> e)
        {
        }

        [TestMethod]
        public void General_FunctionalTest()
        {
            SmartEntityTypeLevelLibrary.Global.RegisterFieldEffectForType<decimal>(typeof(TestEntity), "MemberField", EntityLevel_Effect);
            SmartEntityTypeLevelLibrary.Global.RegisterFieldEffectForType<decimal>(typeof(ParentEntity), "OwnedTestEntity.MemberField", MidLevel_Effect);
            SmartEntityTypeLevelLibrary.Global.RegisterFieldEffectForType<decimal>(typeof(ParentEntity2), "ChildEntity.OwnedTestEntity.MemberField", ParentLevel_Type_Effect);


            ParentEntity2 newEntity = new ParentEntity2();

            newEntity.AddFieldEffect<decimal>("ChildEntity.OwnedTestEntity.MemberField", ParentLevel_Instance_Effect);

            // newEntity.RegisterFieldEffectForType(newEffect);
            TestEntity temp = newEntity.ChildEntity["OwnedTestEntity"] as TestEntity;
            temp.MemberField.Value = 123;
        }

        #endregion

        #region Private Static Methods

 
        #endregion

        #region Fields and Constants

        private TestContext testContextInstance;

        #endregion

                class TestEntity : SmartEntity
        {
            [AutoField]
            public ISmartField<decimal> MemberField { get; private set; }
            [AutoField]
            public ISmartField<decimal> OtherField { get; private set; }
        }


        #region Public Instance Properties

        public ISmartField<long> m_TestField { get; set; }
        public ISmartField<string> m_EchoField { get; set; }

        #endregion

        class ParentEntity : SmartEntity
        {
            public ParentEntity()
            {
                OwnedTestEntity = new TestEntity();
                LinkedTestEntity.LinkedEntity = OwnedTestEntity;
                RegisterField("OwnedTestEntity", OwnedTestEntity);
            }
            [AutoField(AutoCreate = false)]
            public TestEntity OwnedTestEntity { get; private set; }
 
            [AutoField]
            public SmartEntityLink<TestEntity> LinkedTestEntity { get; private set; }

        }
        class ParentEntity2 : SmartEntity
        {
            public ParentEntity2()
            {
                ChildEntity.LinkedEntity = new ParentEntity();
                RegisterFieldEffectForType<decimal>("ChildEntity.OwnedTestEntity.MemberField", Embedded_TypeLevel_Effect);
                ChildEntity.AddFieldEffect<decimal>("OwnedTestEntity.MemberField", Embedded_InstanceLevel_Effect);
                ChildEntity.AddFieldEffect<decimal>("LinkedTestEntity.MemberField", Embedded_LinkedInstanceLevel_Effect);
            }
            [AutoField]
            public SmartEntityLink<ParentEntity> ChildEntity { get; private set; }

            void Embedded_TypeLevel_Effect(object sender, ValueChangedEventArgs<decimal> e)
            {
            }

            void Embedded_InstanceLevel_Effect(object sender, ValueChangedEventArgs<decimal> e)
            {
            }

            void Embedded_LinkedInstanceLevel_Effect(object sender, ValueChangedEventArgs<decimal> e)
            {
            }

        }


    }
}